<?php
@include_once("conn.php");

$page = $_GET["page"];
$shownum = $_GET["shownum"];
if ($page && $shownum) {
    $skipnum = ($page - 1) * $shownum;

    $sql = "select  * from  goods_list  limit $skipnum,$shownum"; //跳过多少条 显示多少条

    $sql1 = "select  count(*) from  goods_list"; //只会有一条数据

    // echo $sql;
    $result  = mysqli_query($conn, $sql);

    $result1 = mysqli_query($conn, $sql1);
    $list = array(); //作为对象用

    $item1 = mysqli_fetch_array($result1);

    $list["count"] = $item1[0];


    $arr = array(); //集合
    while ($item = mysqli_fetch_array($result)) {
        $temp = array(); //当对象用

        $temp["id"] = $item["id"];
        $temp["goodsname"] = $item["goodsname"];
        $temp["goodsimg"] = $item["goodsimg"];
        $temp["goodsprice"] = $item["goodsprice"];
        $temp["goodsnum"] = $item["goodsnum"];


        $arr[] = $temp; //往集合里面丢对象
    }
    $list["list"] = $arr;



    echo json_encode($list);
}
